/**
 * 
 */
package org.tcp.client.pool.imp;

import java.util.HashMap;
import java.util.Map;

import org.tcp.client.exception.ExceptionEnum;
import org.tcp.client.exception.PoolException;
import org.tcp.client.pool.PoolConfig;

/**
 * @author kucheng.liao@autonavi.com
 * @Date Sep 19, 2014
 */
public class DefaultPoolConfig implements PoolConfig {

	protected Map<PoolConfigEnum, String> parameterMaps = new HashMap<PoolConfigEnum, String>();

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tcp.client.pool.PoolConfig#getConfig()
	 */
	public Map<PoolConfigEnum, String> getConfig() {
		if (validate()) {
			return parameterMaps;
		}
		throw new PoolException(ExceptionEnum.PARAMETER_EXCEPTION);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tcp.client.pool.PoolConfig#validate()
	 */
	public boolean validate() {
		if (null == parameterMaps) {
			return false;
		}
		if (!parameterMaps.containsKey(PoolConfigEnum.HEAT_TIME)) {
			parameterMaps.put(PoolConfigEnum.HEAT_TIME, "1000");
		}
		if (!parameterMaps.containsKey(PoolConfigEnum.HEAT_PRO)) {
			parameterMaps.put(PoolConfigEnum.HEAT_PRO, "heat jump data");
		}
		if (!parameterMaps.containsKey(PoolConfigEnum.HEAT_TEST_TIME)) {
			parameterMaps.put(PoolConfigEnum.HEAT_TEST_TIME, "3");
		}
		for (PoolConfigEnum e : PoolConfigEnum.values()) {
			if (!parameterMaps.containsKey(e)) {
				return false;
			}
		}
		return true;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tcp.client.pool.PoolConfig#add(java.lang.Object,
	 * java.lang.Object)
	 */
	public void add(PoolConfigEnum k, String v) {
		parameterMaps.put(k, v);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.tcp.client.pool.PoolConfig#addAll(java.util.Map)
	 */
	public void addAll(Map<PoolConfigEnum, String> parameters) {
		parameterMaps.putAll(parameters);
	}

}
